
var pos = 0;
	var ctx = null;
	var cam = null;
	var image = null;

	var filter_on = false;
	var filter_id = 0;

	function changeFilter() {
		if (filter_on) {
			filter_id = (filter_id + 1) & 7;
		}
	}

	function toggleFilter(obj) {
		alert("222");
		if (filter_on =!filter_on) {
			obj.parentNode.style.borderColor = "#c00";
		} else {
			obj.parentNode.style.borderColor = "#333";
		}
	}
	
	$("#webcam").webcam({

		width: 320,
		height: 240,
		mode: "save",
		swffile: "/js/webcam/jscam.swf",

		onTick: function(remain) {

			if (0 == remain) {
				jQuery("#status").text("Cheese!");
			} else {
				jQuery("#status").text(remain + " seconds remaining...");
			}
		},

		onCapture: function () {			
			var s = this.save('emp.php?do=Info.upload');
		},

		debug: function (type, string) {
			$("#status").html(type + ": " + string);
		},

		onLoad: function () {

			var cams = webcam.getCameraList();
			for(var i in cams) {
				$("#cams").append("<li>" + cams[i] + "</li>");
			}
		}
	});

	
	window.addEventListener("load", function() {

		$("body").append("<div id=\"flash\"></div>");

		var canvas = document.getElementById("canvas");

		if (canvas.getContext) {
			ctx = document.getElementById("canvas").getContext("2d");
			ctx.clearRect(0, 0, 200, 240);

			var img = new Image();
			img.src = "/static/logo.gif";
			img.onload = function() {
				ctx.drawImage(img, 129, 89);
			}
			image = ctx.getImageData(0, 0, 200, 240);
		}
		
		var pageSize = getPageSize();
		$("#flash").css({ height: pageSize[1] + "px" });

	}, false);

	window.addEventListener("resize", function() {

		var pageSize = getPageSize();
		jQuery("#flash").css({ height: pageSize[1] + "px" });

	}, false);

	

function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth, pageHeight];
}


$.extend({
	add: function(a, b) {
		return a+b;
	}
});

$.fn.extend({
	color: function(val) {
		if (val == undefined) {
			return $(this).css("color");
		} else {
			return $(this).css("color", val);
		}
	}
});

var tec = {
	
	add: function(a, b) {
		return a+b;
	},
	
	dec: function(a, b) {
		return a-b;
	}
};

$.extend(tec, {
	mul: function(a, b) {
		return a*b;
	},
	
	div: function(a, b) {
		return a/b;
	}
});

function test(s) {
	alert(tec.mul(2,4));
	
	// alert($.add(2, 3));
	// $("#result").color("red");
	
	/*
	if (mold_name(s)) {
		alert("ok");
	} else {
		alert("22");
	}*/
}

function quote_name(s) {
	if (s == null || s.trim() == '') {
		return true;
	}

	var value = s.trim();
	var regex;

	regex = /^(GM|TM|T)(\d+)\.(\d+)$/
	if (regex.test(value)) {
		return true;
	}

	return false;
}


function mold_name(s) {
	if (s == null || s.trim() == '') {
		return true;
	}

	var value = s.trim();
	var regex;

	regex = /^(GM|TM|T)(\d+)\.(\d+)-(\d+)$/
	if (regex.test(value)) {
		return true;
	}
	
	regex = /^(GM|TM|T)(\d+)\.(\d+)$/
	if (regex.test(value)) {
		return true;
	}

	return false;
}

function vcf() {
	var url = "emp.php?do=Emp.vcf";
	$.get(url);	
}

function status() {
	var url = "/monast/status.php";	
	
	var body = {};
	body.reqTime = new Date().getTime();
	
	$.getJSON(url, body, function(json) {
		alert($.toJSON(json));
	});
	
	// alert(url);
}